package hw;

import sk.Util;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;

public class ATM extends JFrame {
    private ArrayList<User> users = new ArrayList();
    private LoginPanel loginPanel = new LoginPanel(this);
    private MenuPanel menuPanel = new MenuPanel(this);
    private SavePanel savePanel = new SavePanel(this);
    private GetPanel getPanel = new GetPanel(this);
    private LookPanel lookPanel = new LookPanel(this);
    private TransPanel transPanel = new TransPanel(this);
    private ModifyPanel modifyPanel = new ModifyPanel(this);
    private Image bgImg = Util.getImage("/images/background.jpg");
    private CardLayout cardLayout = new CardLayout();

    private int num;


    public ATM() {
        init();
        this.setContentPane(new JPanel() {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.drawImage(bgImg, 0, 0, 1024, 768, this);
            }
        });

        //初始化窗体
        this.setSize(1024, 768);
        this.setLocationRelativeTo(this);
        this.setLayout(cardLayout);
        this.setTitle("ATM");
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);

        //添加卡片
        this.add("login", loginPanel);
        this.add("menu", menuPanel);
        this.add("save", savePanel);
        this.add("get", getPanel);
        this.add("look", lookPanel);
        this.add("trans", transPanel);
        this.add("modify", modifyPanel);

        this.setVisible(true);

    }

    //初始化用户
    public void init() {
        users.add(new User("zhangsan", "123", 500));
        users.add(new User("lisi", "456", 1000));
        users.add(new User("wangwu", "789", 1500));
        users.add(new User("zhaoliu", "666", 2000));
        users.add(new User("wu", "888", 2500));
        users = (ArrayList<User>) FileUtil.readObject("d:\\user.txt");
    }

    public ArrayList<User> getUsers() {
        return users;
    }

    public void setUsers(ArrayList<User> users) {
        this.users = users;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public LookPanel getLookPanel() {
        return lookPanel;
    }

    public void setLookPanel(LookPanel lookPanel) {
        this.lookPanel = lookPanel;
    }


    public void switchPanel(String name) {
        cardLayout.show(this.getContentPane(), name);
    }


    public static void main(String[] args) {
        ATM atm = new ATM();

    }


}
